<template>
  <div class="">
    <div class="loadHomeWorkIneer">
      <div class="loadTopAndSelect">
        <div class="loadTop1">装载作业</div>

        <el-select
          class="mySelect"
          :no-data-text="'无数据'"
          size="small"
          style="width: 100px; height: 20px; margin-left: 10px"
          v-model="valueSelect"
          @change="changeLoad"
        >
          <el-option label="LNG" value="LNG" />
          <el-option label="甲醇" value="甲醇" />
        </el-select>
        <div class="loadTop1" style="font-size: 15px">选择年份</div>

        <el-select
          class="mySelect"
          placeholder="选择年份"
          size="small"
          style="width: 100px; height: 20px; margin-left: 10px"
          v-model="chooseYear"
          clearable
          @change="chageSelect()"
        >
          <el-option v-for="item in yearList" :label="item" :value="item" />
        </el-select>
        <div class="loadTop1" style="font-size: 15px">选择船</div>

        <el-select
          class="mySelect"
          placeholder="选择船"
          size="small"
          clearable
          @change="chageSelect()"
          style="width: 100px; height: 20px; margin-left: 10px"
          v-model="chooseShip"
        >
          <el-option label="海港未来" value="海港未来" />
          <el-option label="淮河能源启航" value="淮河能源启航" />
        </el-select>
      </div>

      <div class="loadAndSearch">
        <div class="loadExcel">
          <div class="button" type="success" @click="uploadFile()">导入</div>
          <div class="button" type="success" @click="getExcelFile()">导出</div>
          <div class="button" type="success" @click="addOne()">新增</div>
          <div class="multiButton" type="success" @click="deleteMulti()">
            删除
          </div>
        </div>
        <div class="search">
          <input
            type="text"
            placeholder="加注专员/作业地点/受注船/船东代表"
            v-model="filledMany"
            @input="changeText()"
          />
          <div class="searchButton" @click="getRenderList()">搜索</div>
        </div>
      </div>
      <div class="table" :style="{ width: tableWidth }">
        <el-table
          v-if="showSummery == '否'"
          empty-text="暂无数据"
          :header-cell-style="{
            background: '#FAFAFA',
            color: '#777676 !important',
            fontWeight: '800',
          }"
          :data="tableData"
          @row-dblclick="handleRowDblclick"
          :row-style="{ height: 30 + 'px' }"
          :cell-style="{ padding: 0 + 'px' }"
          border
          stripe
          style="width: 100%; height: auto"
          max-height="65vh"
          @selection-change="selecttableFunction"
        >
          <el-table-column type="selection" width="35" align="center" />

          <el-table-column
            type="index"
            :index="indexNumber"
            align="center"
            label="序号"
            width="50"
          >
          </el-table-column>

          <el-table-column
            prop="homeworkMonth"
            label="作业月份"
            align="center"
            min-width="75"
          />
          <el-table-column
            prop="homeworkNum"
            label="作业编号"
            min-width="100"
            align="center"
          >
          </el-table-column>
          <el-table-column
            label="作业开始时间"
            min-width="90"
            prop="startDate"
            align="center"
            :formatter="formatDate"
          />
          <el-table-column
            label="作业结束时间"
            min-width="90"
            prop="endDate"
            align="center"
            :formatter="formatDate"
          />
          <el-table-column
            prop="homeworkLocation"
            label="作业地点"
            align="center"
            min-width="90"
          /><el-table-column
            prop="filledShip"
            label="受注船"
            align="center"
            min-width="100"
          />
          <el-table-column label="装载量" align="center" min-width="100">
            <el-table-column
              prop="imi_MMBtu"
              label="装载量热值(MMBUT)"
              align="center"
              min-width="195"
            />
            <el-table-column
              prop="imi_volume"
              label="装载量体积(m³)"
              align="center"
              min-width="195"
            />
            <el-table-column
              prop="imi_weight"
              label="重量(t)"
              align="center"
              min-width="195"
            />
          </el-table-column>
          <el-table-column
            prop="fillPeople"
            label="加注专员"
            align="center"
            min-width="85"
          /><el-table-column
            prop="shipownerPeople"
            label="船东代表"
            align="center"
            min-width="85"
          /><el-table-column
            prop="includeFlag"
            label="是否计入图表"
            align="center"
            :formatter="formatincludeFlag"
            min-width="100"
          />
        </el-table>
        <el-table
          v-else
          empty-text="暂无数据"
          :header-cell-style="{ background: '#FAFAFA' }"
          :data="tableData"
          @row-dblclick="handleRowDblclick"
          :row-style="{ height: 30 + 'px' }"
          :cell-style="{ padding: 0 + 'px' }"
          show-summary
          :summary-method="getSummaries"
          border
          stripe
          style="width: 100%; height: auto"
          max-height="65vh"
          @selection-change="selecttableFunction"
        >
          <el-table-column type="selection" width="35" align="center" />

          <el-table-column
            type="index"
            :index="indexNumber"
            align="center"
            label="序号"
            width="50"
          >
          </el-table-column>

          <el-table-column
            prop="homeworkMonth"
            label="作业月份"
            align="center"
            min-width="75"
          />
          <el-table-column
            prop="homeworkNum"
            label="作业编号"
            min-width="100"
            align="center"
          >
          </el-table-column>
          <el-table-column
            label="作业开始时间"
            min-width="90"
            prop="startDate"
            align="center"
            :formatter="formatDate"
          />
          <el-table-column
            label="作业结束时间"
            min-width="90"
            prop="endDate"
            align="center"
            :formatter="formatDate"
          />
          <el-table-column
            prop="homeworkLocation"
            label="作业地点"
            align="center"
            min-width="90"
          /><el-table-column
            prop="filledShip"
            label="受注船"
            align="center"
            min-width="100"
          />
          <el-table-column label="装载量" align="center" min-width="100">
            <el-table-column
              prop="imi_MMBtu"
              label="装载量热值(MMBUT)"
              align="center"
              min-width="195"
            />
            <el-table-column
              prop="imi_volume"
              label="装载量体积(m³)"
              align="center"
              min-width="195"
            />
            <el-table-column
              prop="imi_weight"
              label="重量(t)"
              align="center"
              min-width="195"
            />
          </el-table-column>
          <el-table-column
            prop="fillPeople"
            label="加注专员"
            align="center"
            min-width="85"
          /><el-table-column
            prop="shipownerPeople"
            label="船东代表"
            align="center"
            min-width="85"
          /><el-table-column
            prop="includeFlag"
            label="是否计入图表"
            align="center"
            :formatter="formatincludeFlag"
            min-width="100"
          />
        </el-table>
        <!-- 内容过多，会出现滚动条 -->
      </div>

      <div class="foot">
        <div class="currentPage">当前第{{ page }}/{{ totalPages }}页</div>
        <div
          class="lastPage"
          :style="{ background: color }"
          @click="clickLastPage()"
        >
          上一页
        </div>
        <div
          class="nextPage"
          :style="{ backgroundColor: color1 }"
          @click="clickNextPage()"
        >
          下一页
        </div>
        <div class="currentNumber">共{{ totalNumber }}条</div>
        <div>跳转至:</div>
        <input
          type="text"
          class="skipPage"
          style="width: 50px !important"
          v-model="shipPageNumer"
        />
        <div class="sureSkip" @click="skipPage">确定</div>
      </div>
    </div>
    <div class="dialog" ref="dialog" :style="{ display: show }">
      <div class="loadHomeWorkIneer">
        <div class="changeTop">
          <div
            class="delete"
            @click="deleteOne(id)"
            v-show="addOrEdit == '编辑'"
          >
            删除
          </div>
          <div class="sure" @click="sureAdd()">确认</div>
          <div class="back" @click="backToIndex()">返回</div>
        </div>
        <div class="dialogText">{{ addOrEdit }}</div>
        <div class="manyInput">
          <div class="iuptInnerContain">
            <div class="inputInner">
              <div class="name">作业月份:</div>
              <el-select
                class="mySelect"
                :no-data-text="'无数据'"
                v-model="homeworkMonth"
                placeholder="作业月份"
                size="default"
                style="width: 220px; margin-left: 5px"
              >
                <el-option v-for="item in 12" :label="item" :value="item" />
              </el-select>
            </div>
            <div class="inputInner">
              <div class="name">作业编号:</div>
              <input type="text" placeholder="作业编号" v-model="homeworkNum" />
            </div>
            <div class="inputInner">
              <div class="name">作业开始时间:</div>

              <div class="inputContainer">
                <el-config-provider :locale="locale">
                  <el-date-picker
                    v-model="startDate"
                    type="date"
                    placeholder="作业开始时间"
                    format="YYYY/MM/DD"
                    value-format="YYYY/MM/DD"
                    @change="handleStartDateChange"
                  />
                </el-config-provider>
              </div>
            </div>
            <div class="inputInner">
              <div class="name">作业结束时间:</div>
              <div class="inputContainer">
                <el-config-provider :locale="locale">
                  <el-date-picker
                    v-model="endDate"
                    type="date"
                    placeholder="作业结束时间"
                    format="YYYY/MM/DD"
                    value-format="YYYY/MM/DD"
                    :picker-options="endPickerOptions"
                    @change="handleEndDateChange"
                  />
                </el-config-provider>
              </div>
            </div>

            <div class="inputInner">
              <div class="name">作业地点:</div>
              <el-select
                style="width: 220px; margin-left: 5px"
                v-model="homeworkLocation"
                :no-data-text="'无数据'"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in placeList"
                  :label="item.name"
                  :value="item.name"
                ></el-option>
              </el-select>
              <!-- <input
                type="text"
                name=""
                id=""
                placeholder="作业地点"
                v-model="homeworkLocation"
              /> -->
            </div>
            <div class="inputInner">
              <div class="name">受注船:</div>
              <input
                type="text"
                name=""
                id=""
                placeholder="受注船"
                v-model="filledShip"
              />
            </div>
            <div class="inputInner">
              <div class="name">装载量热值:</div>
              <input
                type="number"
                name=""
                id=""
                placeholder="装载量热值"
                v-model="imi_MMBtu"
              />
            </div>
            <div class="inputInner">
              <div class="name">装载量体积:</div>
              <input
                type="number"
                name=""
                id=""
                placeholder="装载量体积"
                v-model="imi_volume"
              />
            </div>
            <div class="inputInner">
              <div class="name">重量:</div>
              <input
                type="number"
                name=""
                id=""
                placeholder="重量"
                v-model="imi_weight"
              />
            </div>
            <div class="inputInner">
              <div class="name">加注专员:</div>
              <input
                type="text"
                name=""
                id=""
                placeholder="加注专员"
                v-model="fillPeople"
              />
            </div>
            <div class="inputInner">
              <div class="name">船东代表:</div>
              <input
                type="text"
                name=""
                id=""
                placeholder="船东代表"
                v-model="shipownerPeople"
              />
            </div>
            <div class="inputInner">
              <div class="name">是否计入图表:</div>
              <input
                type="text"
                oninput="value=value.replace(/[^0|1]/g,'').slice(0,1)"
                name=""
                id=""
                placeholder="是否计入图表(1:是;0:否)"
                v-model="includeFlag"
              />
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="dialog2" :style="{ display: uploadfile }">
      <div class="upContain">
        <input
          type="file"
          ref="clearFile"
          class="addfile"
          @change="getFile($event)"
          accept=".xls,.xlsx"
        />
      </div>
      <div class="fileName">
        <div v-show="fileName">文件名:{{ fileName }}</div>
      </div>
      <div class="upFileSrue">
        <button class="buttonUpdata" @click="cancelUp()">取消</button>
        <button class="buttonUpdata buttonUpdata1" @click="submitAddFile()">
          确定
        </button>
      </div>
    </div>
  </div>
</template>
<script>
import EventBus from "@/mitt/eventBus.js";
import rename from "@/mitt/getPath.js";
import service from "@/api/api";
import _ from "lodash";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import axios from "axios";
import qs from "qs";
export default {
  name: "",
  data() {
    return {
      filledMany: "",
      yearList: [],
      chooseYear: "",
      chooseShip: "",
      compare: {},
      showSummery: "是",
      shipPageNumer: 1,
      placeList: [],
      multi: [],
      token: "",
      leftWidth: "",
      locale: zhCn,
      userName: "",
      left: "left1",
      naveLeft: true,
      menuList: [],
      totalNumber: 0,
      tableData: [],
      changeLeftSize: true,
      changeName: "",
      icon: "Fold",
      showQuit: false,
      menu: "menu1",
      iconSize: 15,
      changeLeft: "child1",
      page: 1,
      size: 20,
      pageList: [],
      show: "none",
      addOrEdit: "新增",
      currentNum: 0,
      endDate: "",
      fillPeople: "",
      filledShip: "",
      homeworkLocation: "",
      homeworkMonth: "",
      homeworkNum: "",
      imi_MMBtu: "",
      imi_volume: "",
      imi_weight: "",
      includeFlag: "",
      tableWidth: null,
      serialNumber: "",
      shipownerPeople: "",
      startDate: "",
      totalPages: null,
      id: "",
      uploadfile: true,
      data: {
        endDate: "",
        fillPeople: "",
        filledShip: "",
        homeworkLocation: "",
        homeworkMonth: "",
        homeworkNum: "",
        imi_MMBtu: "",
        imi_volume: "",
        imi_weight: "",
        includeFlag: "",
        serialNumber: "",
        shipownerPeople: "",
        startDate: "",
        id: "",
      },
      valueSelect: "LNG",
      show1: "none",
      color: "#EBEBEB",
      color1: "#EBEBEB",
      file: null,
      fileName: "",
      jtData: null,
      endPickerOptions: {
        disabledDate: (time) => {
          // 默认情况下，结束日期不能早于开始日期
          if (this.startDate) {
            return time.getTime() < this.startDate.getTime();
          }
          return false;
        },
      },
    };
  },

  methods: {
    chageSelect() {
      this.page = 1;
      this.getRenderList();
    },
    async findYear() {
      await service({
        methods: "get",
        url: "/load-data/get-year",
      })
        .then((e) => {
          this.yearList = e.data;
        })
        .catch((err) => {});
    },
    async findAllType() {
      await service({
        methods: "get",
        url: "/dict-type/find-all",
      })
        .then((e) => {

          // this.containList = e.data;
          for (let i = 0; i < e.data.length; i++) {
            if (e.data[i].name == "作业地点") {

              this.getPlace(e.data[i].typeKey);
            }
          }
          this.getRenderList();
        })
        .catch((err) => {});
    },
    async getPlace(type) {
      let data = {
        typeKey: type,
      };

      await service({
        methods: "get",
        url: "dict-type/find-dict-item-list",
        params: data,
      })
        .then((e) => {
          this.placeList = e.data;
        })
        .catch((err) => {
          this.$message({
            message: "获取数据失败",
            type: "info",
          });
        });
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }
        if (
          index === 1 ||
          index === 2 ||
          index === 3 ||
          index === 4 ||
          index === 5 ||
          index === 6 ||
          index === 7 ||
          index === 11 ||
          index === 12 ||
          index === 13
        ) {
          sums[index] = "";
          return;
        }

        const values = data.map((item) => Number(item[column.property]));

        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return parseInt(prev + curr);
            } else {
              return prev;
            }
          }, 0);
        }
      });

      // sums[12] = Math.ceil(sums[12] * Math.pow(10, 2) - 0.5) / Math.pow(10, 2);
      // sums[13] = Math.ceil(sums[13] * Math.pow(10, 2) - 0.5) / Math.pow(10, 2);
      return sums;
    },
    indexNumber(index) {
      return (this.page - 1) * this.size + index + 1;
    },
    changeLoad() {
      if (this.valueSelect == "LNG") {
        this.$router.push("/app.load1");
      } else if (this.valueSelect == "甲醇") {
        this.$router.push("/app.load2");
      }
    },

    handleRowDblclick(row) {
      this.clickEdit(row.id);
    },
    // 监听第一个日期选择器的值变化
    handleStartDateChange() {
      if (this.startDate && this.endDate && this.startDate > this.endDate) {
        // 如果开始日期晚于结束日期，提示用户并重置结束日期
        this.$message.warning("开始时间不能晚于结束时间，已重置结束时间");
        this.endDate = null;
      }

      // 更新第二个日期选择器的可选范围
      this.endPickerOptions = {
        disabledDate: (time) => {
          // 结束日期不能早于开始日期
          if (this.startDate) {
            return time.getTime() < this.startDate.getTime();
          }
          return false;
        },
      };
    },
    // 监听第二个日期选择器的值变化
    handleEndDateChange() {
      if (this.startDate && this.endDate && this.endDate < this.startDate) {
        // 如果结束日期早于开始日期，提示用户并重置结束日期
        this.$message.warning("结束时间不能早于开始时间，已重置结束时间");
        this.endDate = null;
      }
    },

    // 跳转页面
    skipPage() {
      if (this.shipPageNumer <= this.totalPages && this.shipPageNumer > 0) {
        this.page = this.shipPageNumer;
        this.getRenderList();
      } else {
        this.$message({
          type: "warning",
          message: "超出页面数量范围",
        });
      }
    },

    // 批量删除开始========================
    selecttableFunction(row) {
      if (row.length > 0) {
        this.multi = [];
        row.forEach((element) => {
          this.multi.push(element.id);
        });
      } else {
        this.multi = [];
      }
    },
    deleteMulti() {
      // let that = this;
      if (this.multi.length == 0) {
        return this.$message({
          type: "warning",
          message: "请先选中再进行批量删除操作！",
        });
      }
      let data = {
        idList: this.multi + "",
      };

      this.$alert("确定删除选中的信息？", {
        confirmButtonText: "确定",
        callback: (action) => {

          if (action == "confirm") {
            service({
              method: "delete",
              url: `/load-data`,
              params: data,
            }).then((r) => {
              if (r.status == "SUCCESS") {
                this.$message({
                  type: "success",
                  message: "删除成功",
                });
                if (this.currentNum == this.multi.length && this.page > 1) {
                  this.page--;
                }
                this.getRenderList();
              }
            });
          } else {
            this.$message({
              type: "info",
              message: "取消删除",
            });
          }
        },
      });
    },
    //批量删除结束=============================
    formatincludeFlag(row, column) {
      // 获取单元格数据
      let data = row[column.property];

      if (data == 0) {
        return 0;
      } else if (data == 1) {
        return 1;
      } else {
        return "";
      }
    },
    formatDate(row, column) {
      // 获取单元格数据

      let data = row[column.property];

      if (data == null) {
        return null;
      }
      let date = new Date(data);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      return `${year}/${month}/${day}`;
    },
    customIndex(index) {
      return (this.page - 1) * this.size + index + 1;
      // 自定义序号显示，比如增加分页后的偏移量
      // return (this.page - 1) * this.size + index + 1;
    },
    // 导入文件================
    uploadFile() {
      this.uploadfile = "block";
    },
    getFile(event) {
      this.file = event.target.files[0];
      this.fileName = this.file.name;

    },
    submitAddFile() {
      if (this.file) {
        let data = {
          file: this.file,
        };
        service({
          method: "post",
          url: "/load-data/upload",
          headers: {
            "Content-Type": "multipart/form-data",
          },
          data: data,
        })
          .then((res) => {
            document.getElementsByClassName("addfile")[0].value = "";
            this.$message({
              message: "上传成功",
              type: "success",
            });
            this.file = "";
            this.fileName = "";
            this.uploadfile = "none";
            this.getRenderList();
          })
          .catch((err) => {
            this.$message({
              message: err,
              type: "fail",
            });
          });
      } else {
        this.$message({
          message: "请先选择文件再上传",
          type: "warning",
        });
      }
    },
    cancelUp() {
      this.file = "";
      this.fileName = "";
      this.uploadfile = "none";
    },
    // 导入文件结束=============
    backToIndex() {
      if (this.addOrEdit == "编辑") {
        let data = {
          endDate: this.endDate,
          fillPeople: this.fillPeople,
          filledShip: this.filledShip,
          homeworkLocation: this.homeworkLocation,
          homeworkMonth: this.homeworkMonth,
          homeworkNum: this.homeworkNum,
          imi_MMBtu: this.imi_MMBtu,
          imi_volume: this.imi_volume,
          imi_weight: this.imi_weight,
          includeFlag: this.includeFlag,
          shipownerPeople: this.shipownerPeople,
          startDate: this.startDate,
        };
        let equal = _.isEqual(data, JSON.parse(this.compare));
        if (equal) {
          this.close();
        } else {
          this.$confirm("数据信息有变化是否保存再离开？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            // type: "warning",
          })
            .then(() => {
              this.sureAdd();
            })
            .catch(() => {
              this.close();
            });
        }
      } else if (this.addOrEdit == "新增") {
        this.close();
      }
    },
    clickEdit(a) {
      this.addOrEdit = "编辑";


      this.tableData.forEach((item) => {
        if (item.id == a) {
          this.endDate = item.endDate;
          this.fillPeople = item.fillPeople;
          this.filledShip = item.filledShip;
          this.homeworkLocation = item.homeworkLocation;
          this.homeworkMonth = item.homeworkMonth;
          this.homeworkNum = item.homeworkNum;
          this.imi_MMBtu = item.imi_MMBtu;
          this.imi_volume = item.imi_volume;
          this.imi_weight = item.imi_weight;
          this.includeFlag = item.includeFlag;
          this.serialNumber = item.serialNumber;
          this.shipownerPeople = item.shipownerPeople;
          this.startDate = item.startDate;
          this.id = a;
          this.compare = JSON.stringify({
            endDate: item.endDate,
            fillPeople: item.fillPeople,
            filledShip: item.filledShip,
            homeworkLocation: item.homeworkLocation,
            homeworkMonth: item.homeworkMonth,
            homeworkNum: item.homeworkNum,
            imi_MMBtu: item.imi_MMBtu,
            imi_volume: item.imi_volume,
            imi_weight: item.imi_weight,
            includeFlag: item.includeFlag,
            serialNumber: item.serialNumber,
            shipownerPeople: item.shipownerPeople,
            startDate: item.startDate,
          });
        }
        this.show = "block";
      });
    },

    // 删除数据
    deleteOne(a) {
      // let that = this;
      this.$alert("确定删除这条信息？", {
        confirmButtonText: "确定",
        callback: (action) => {

          if (action == "confirm") {
            service({
              method: "delete",
              url: `/load-data/${a}`,
            }).then((r) => {
              if (r.status == "SUCCESS") {
                this.$message({
                  type: "success",
                  message: "删除成功",
                });
                if (this.currentNum == 1 && this.page > 1) {
                  this.page--;
                }
                this.getRenderList();
                this.show = "none";
              }
            });
          } else {
            this.$message({
              type: "info",
              message: "取消删除",
            });
          }
        },
      });
    },
    // 弹窗确认按钮
    sureAdd() {

      this.data.endDate = this.endDate;
      this.data.fillPeople = this.fillPeople;
      this.data.filledShip = this.filledShip;
      this.data.homeworkLocation = this.homeworkLocation;
      this.data.homeworkMonth = this.homeworkMonth;
      this.data.homeworkNum = this.homeworkNum;
      this.data.imi_MMBtu = this.imi_MMBtu;
      this.data.imi_volume = this.imi_volume;
      this.data.imi_weight = this.imi_weight;
      this.data.includeFlag = this.includeFlag;
      this.data.serialNumber = this.serialNumber;
      this.data.shipownerPeople = this.shipownerPeople;
      this.data.startDate = this.startDate;
      this.data.id = this.id;
      if (this.addOrEdit == "编辑") {
        service({
          method: "put",
          data: this.data,
          url: "/load-data",
        })
          .then((r) => {
            if (r.status == "SUCCESS") {
              this.$message({
                type: "success",
                message: "修改成功",
              });
              this.clearCanShu();
              this.getRenderList();
              this.show = "none";
            }
          })
          .catch((err) => {
            this.$message({
              type: "info",
              message: "出错了！",
            });
          });
      } else {
        service({
          method: "post",
          data: this.data,
          url: "/load-data",
        })
          .then((r) => {
            if (r.status == "SUCCESS") {
              this.$message({
                type: "success",
                message: "新增成功",
              });
              this.clearCanShu();
              this.getRenderList();
              this.show = "none";
            }
          })
          .catch((err) => {
            this.$message({
              type: "info",
              message: "出错了！",
            });
          });
      }
    },
    reduceDate(a) {
      let date = new Date(a);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      return `${year}-${month}-${day}`;
    },
    // 关闭弹窗
    close() {
      this.show = "none";
      this.show1 = "none";
      this.clearCanShu();
      this.uploadfile = "none";
    },
    // 新增
    addOne() {
      let that = this;
      this.addOrEdit = "新增";
      // this.$refs["dialog"].style.display = show;
      this.show = "block";
    },
    // 导出文件
    getFileName() {
      let date = new Date();
      let year = date.getFullYear().toString();
      let month =
        date.getMonth() + 1 > 9
          ? date.getMonth() + 1
          : "0" + (date.getMonth() + 1);
      let day =
        date.getDate() > 10 ? date.getDate().toString() : "0" + date.getDate();
      let hour =
        date.getHours() > 10
          ? date.getHours().toString()
          : "0" + date.getHours();
      let min =
        date.getMinutes() > 10
          ? date.getMinutes().toString()
          : "0" + date.getMinutes();

      date = null;
      return `${year}${month}${day}${hour}${min}`;
    },
    async getExcelFile() {
      let that = this;
      let time = this.getFileName();

      this.token = sessionStorage.getItem("token");
      this.token = JSON.parse(this.token);
      let data = {};
      if (this.chooseShip && this.chooseYear && this.filledMany) {
        data = {
          year: Number(this.chooseYear),
          filledShip: this.chooseShip,
          text: this.filledMany,
        };
      } else if (this.chooseShip && this.chooseYear) {
        data = {
          year: Number(this.chooseYear),
          filledShip: this.chooseShip,
        };
      } else if (this.chooseShip && this.filledMany) {
        data = {
          text: this.filledMany,
          filledShip: this.chooseShip,
        };
      } else if (this.chooseYear && this.filledMany) {
        data = {
          text: this.filledMany,
          year: Number(this.chooseYear),
        };
      } else if (this.chooseYear) {
        data = {
          year: Number(this.chooseYear),
        };
      } else if (this.chooseShip) {
        data = {
          filledShip: this.chooseShip,
        };
      } else if (this.filledMany) {
        data = {
          text: this.filledMany,
        };
      } else {
        data = {};
      }
      // return;
      axios({
        method: "get",
        url: this.$loadFile + "/load-data/export",
        responseType: "blob", // 关键：设置响应类型为blob

        headers: {
          token: that.token,
        },
        params: data,
      })
        .then((response) => {
          const url = window.URL.createObjectURL(new Blob([response.data]));
          // 创建一个隐藏的<a>标签，并设置其href属性为上面创建的URL
          const link = document.createElement("a");
          link.href = url;

          link.download = "日常装载作业LNG-" + time + ".xls"; // 替

          document.body.appendChild(link);

          link.click();

          document.body.removeChild(link);

          window.URL.revokeObjectURL(url);
        })
        .catch((error) => {
          this.$message({
            message: "文件下载失败",
            type: "info",
          });
        });
    },
    sendMessage() {
      let res = rename();
      EventBus.emit("custom-event", res);
    },
    changeText() {
      this.page = 1;

    },

    // 获取列表数据
    async getRenderList() {
      let data = {};

      if (this.filledMany) {
        if (this.chooseYear && this.chooseShip) {
          data = {
            page: this.page,
            size: this.size,
            text: this.fillPeople,
            year: this.chooseYear,
            filledShip: this.chooseShip,
          };
        } else if (this.chooseYear) {
          data = {
            page: this.page,
            size: this.size,
            text: this.fillPeople,
            year: this.chooseYear,
          };
        } else if (this.chooseShip) {
          data = {
            page: this.page,
            size: this.size,
            text: this.fillPeople,
            filledShip: this.chooseShip,
          };
        } else {
          data = {
            page: this.page,
            size: this.size,
          };
        }
      } else {
        if (this.chooseYear && this.chooseShip) {
          data = {
            page: this.page,
            size: this.size,
            year: this.chooseYear,
            filledShip: this.chooseShip,
          };
        } else if (this.chooseYear) {
          data = {
            page: this.page,
            size: this.size,
            year: this.chooseYear,
          };
        } else if (this.chooseShip) {
          data = {
            page: this.page,
            size: this.size,
            filledShip: this.chooseShip,
          };
        } else {
          data = {
            page: this.page,
            size: this.size,
          };
        }
      }

      await service({
        methods: "get",
        url: "/load-data/find-one-page",
        params: data,
      })
        .then((e) => {
          try {
            if (e.data?.pageData?.content) {
              this.showSummery = "是";
              this.totalPages = e.data.pageData.totalPages;

              this.totalNumber = e.data.pageData.totalElements;
              if (this.totalPages == 0) {
                this.totalPages = 1;
              }
              if (this.page < this.totalPages) {
                this.color1 = "#268FDE";
              } else {
                this.color1 = "#EBEBEB";
              }
              if (this.page == 1) {
                this.color = "#EBEBEB";
              } else {
                this.color = "#268FDE";
              }
              this.tableData = e.data.pageData.content;
              this.currentNum = e.data.pageDate.numberOfElements;
            } else {
              this.showSummery = "否";
              this.totalPages = e.data.totalPages;

              this.totalNumber = e.data.totalElements;
              if (this.totalPages == 0) {
                this.totalPages = 1;
              }
              if (this.page < this.totalPages) {
                this.color1 = "#268FDE";
              } else {
                this.color1 = "#EBEBEB";
              }
              if (this.page == 1) {
                this.color = "#EBEBEB";
              } else {
                this.color = "#268FDE";
              }
              this.tableData = e.data.content;
              this.currentNum = e.data.numberOfElements;
            }
          } catch (error) {}
        })
        .catch((err) => {});
    },
    formatterDate(a) {
      let date = new Date(a);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      return `${year}/${month}/${day}`;
    },
    clearCanShu() {
      this.endDate = "";
      this.fillPeople = "";
      this.filledShip = "";
      this.homeworkLocation = "";
      this.homeworkMonth = "";
      this.homeworkNum = "";
      this.imi_MMBtu = "";
      this.imi_volume = "";
      this.imi_weight = "";
      this.includeFlag = "";
      this.serialNumber = "";
      this.shipownerPeople = "";
      this.startDate = "";
      this.id = "";
      this.data = {
        endDate: "",
        fillPeople: "",
        filledShip: "",
        homeworkLocation: "",
        homeworkMonth: "",
        homeworkNum: "",
        imi_MMBtu: "",
        imi_volume: "",
        imi_weight: "",
        includeFlag: "",
        serialNumber: "",
        shipownerPeople: "",
        startDate: "",
        id: "",
      };
    },
    clickSee(a) {
      this.addOrEdit = "查看";
      this.tableData.forEach((item) => {
        if (item.id == a) {
          this.endDate = item.endDate;
          this.fillPeople = item.fillPeople;
          this.filledShip = item.filledShip;
          this.homeworkLocation = item.homeworkLocation;
          this.homeworkMonth = item.homeworkMonth;
          this.homeworkNum = item.homeworkNum;
          this.imi_MMBtu = item.imi_MMBtu;
          this.imi_volume = item.imi_volume;
          this.imi_weight = item.imi_weight;
          this.includeFlag = item.includeFlag;
          this.serialNumber = item.serialNumber;
          this.shipownerPeople = item.shipownerPeople;
          this.startDate = item.startDate;
        }
        this.show1 = "block";
      });
    },
    clickLastPage() {
      if (this.page > 1) {
        this.page--;
        if (this.page == 1) {
          this.color = "#EBEBEB";
        } else {
          this.color = "#268FDE";
        }
        if (this.page < this.totalPages) {
          this.color1 = "#268FDE";
        }
        this.getRenderList();
      } else {
        this.color = "#EBEBEB";
      }
    },
    clickNextPage() {
      if (this.page < this.totalPages) {
        this.page++;
        this.color = "#268FDE";
        if (this.page == this.totalPages) {
          this.color1 = "#EBEBEB";
        } else {
          this.color1 = "#268FDE";
        }
      }
      this.getRenderList();
    },
    handSize() {
      if (window.innerWidth > 630) {
        if (this.$store.state.width == 200) {
          this.tableWidth = (window.innerWidth - 170) * 0.985 - 20 + "px";
        } else if (this.$store.state.width == 90) {
          this.tableWidth = (window.innerWidth - 60) * 0.985 - 20 + "px";
        }

        // this.changeLeft = "child1";
      } else {
        this.tableWidth = window.innerWidth - 30 + "px";
      }
    },
  },
  watch: {
    "$store.state.width"(newVal, oldVal) {
      //对数据执行操作

      if (window.innerWidth > 630) {
        if (newVal == 90) {
          this.tableWidth = (window.innerWidth - 60) * 0.985 - 20 + "px";
        } else if (newVal == 200) {
          this.tableWidth = (window.innerWidth - 170) * 0.985 - 20 + "px";
        }
      }
       
    },
    $route(to, from) {
      // 在这里根据参数的变化执行刷新页面的逻辑
      if (to.name == from.name) {
        this.close();
      }
    },
  },

  created() {
    this.findAllType();
    this.findYear();
    this.sendMessage();
    this.getRenderList();
  },
  beforeMount() {
    if (window.innerWidth > 630) {
      if (this.$store.state.width == 200) {
        this.tableWidth = (window.innerWidth - 170) * 0.985 - 20 + "px";
      } else if (this.$store.state.width == 90) {
        this.tableWidth = (window.innerWidth - 60) * 0.985 - 20 + "px";
      }
    } else {
      this.tableWidth = window.innerWidth - 30 + "px";
    }
  },
  mounted() {
    let that = this;

    // this.sendMessage();
    window.addEventListener("resize", this.handSize);
  },
  beforeUnmount() {
    window.removeEventListener("resize", this.handSize);
  },
};
</script>
<style lang="less" scoped>
.manyInput {
  width: 780px;
  height: 80vh;
  overflow: auto;
  // background: red;
  margin: auto;

  // overflow: scroll;
  .iuptInnerContain {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    .inputInner {
      width: 375px;
      min-height: 35px;
      // background: blue;
      margin-right: 10px;
      margin-top: 10px;
      display: flex;
      align-items: center;
      // justify-content: space-between;
      color: #365488;
      .name {
        width: 150px;
        height: 100%;
        line-height: 4vh;
        text-align: right;
        font-size: 15px;
      }
      // .name1 {
      //   width: 210px;
      //   margin-left: 10px;
      //   height: 3vh;
      //   line-height: 3vh;
      //   text-indent: 1em;
      //   outline: none;
      //   font-size: 15px;
      //   border: none;
      //   background: #ebebeb;
      //   color: #365488;
      // }
      .inputContainer {
        width: 210px;
        margin-left: 5px;
      }
      .el-input__inner {
        background: white !important;
      }
      input {
        width: 220px;
        height: 34px;
        margin-left: 5px;
        border-radius: 5px;
        text-indent: 1em;
        outline: none;
        border: none;
        background: white !important;
        color: #365488;
        border: 1px solid #dcdfe6;
      }
      input::-webkit-input-placeholder {
        color: #a8abb2;
      }
      input[type="date"] {
        // padding: 5px;
        color: #365488;
        text-align: left;
        // border: 1px solid #365488;
        border-radius: 4px;
        // background-color: #fff;
        box-sizing: border-box; /* 确保内边距和边框不会影响元素的总宽度 */
      }
      // input[type="number"] {
      //   appearance: textfield;
      //   -moz-appearance: textfield;
      // }
      // 　　input[type="number"]::-webkit-inner-spin-button,
      // 　　input[type="number"]::-webkit-outer-spin-button {
      //   -webkit-appearance: none;
      //   margin: 0;
      // }
    }
    .el-date-picker .el-picker-panel {
      background-color: white !important; /* 你想要的背景颜色 */
    }
  }
}
.dialogText {
  margin: auto;
  width: 50%;
  line-height: 4vh;
  font-size: 25px;
  color: black;
  // text-indent: 10px;
  text-align: center;
  // font-size: 20px;
  font-weight: 800;
}

.dialog,
.dialog1 {
  width: 100%;
  height: 100%;
  background: #dfe6e8;
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  z-index: 100;
}

.loadHomeWork {
  overflow: hidden;
  width: 100%;
  height: 100%;
  position: relative;
  .loadHomeWorkIneer {
    width: 98.5%;
    height: 91vh;
    margin: auto;
    margin-top: 1vh;
    background: white;
    .loadTopAndSelect {
      display: flex;
      align-items: center;
      justify-content: baseline;
      .loadTop1 {
        line-height: 40px;
        font-size: 20px;
        color: #777676;
        // text-indent: 10px;
        margin-left: 10px;

        font-weight: 800;
      }
      .loadSelect {
        margin-left: 10px;
        width: 50px;
        height: 20px;
        background: red;
      }
    }

    .loadAndSearch {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;

      .search {
        width: 314px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        // margin-top: 10px;
        margin-right: 10px;
        input {
          width: 250px !important;
          outline: none;
          margin-left: 10px;
          height: 23px;
          text-indent: 10px;
          border: 1px solid #dcdfe6;
        }
        .searchButton {
          width: 64px;
          background: #0470c1;
          font-size: 15px;
          height: 23px;
          text-align: center;
          line-height: 23px;
          // color: #777676;
        }
      }
    }
  }
  // background: blue;
}
.table {
  margin: auto;
  // margin-top: 2vh;
  height: 65vh;
  // background: red;
}

.rigth {
  flex-grow: 1;
  height: 100vh;
  // background: blue;
  .rightTop {
    width: 100%;
    height: 7vh;
    display: flex;
    // background: #3359c7;
    align-items: center;
    justify-content: space-between;
    .topLeft {
      width: 460px;
      display: flex;
      align-items: center;
      height: 100%;
      .changeButton {
        margin-left: 10px;
        width: 40px;
        height: 2.8vh;
        color: #163fb1;
      }
      .NavChangeName {
        // margin-left: 10px;
        font-size: 20px;
        color: #365488;
        width: 140px;
        font-weight: 800;
        display: flex;
        align-items: center;
        justify-content: flex-start;
      }
    }
    .topRight {
      width: 250px;
      height: 100%;
      display: flex;
      position: relative;
      align-items: center;
      // background: red;
      .bell,
      .share {
        color: #3359c7;
        position: relative;
        display: flex;
        align-items: center;
        .messageCircle {
          width: 40px;
          height: 40px;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 50%;
          background: red;
          color: white;
          position: absolute;
          top: -2.4vh;
          left: 0vw;
          transform: scale(0.5);
        }
      }
      .share,
      .avater {
        margin-left: 10px;
      }
      .avater {
        width: 150px;
        height: 100%;
        // background: red;
        display: flex;
        align-items: center;
        .pic {
          width: 50px;
          height: 50px;
          border-radius: 50%;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .userName {
          margin-left: 10px;
          width: 90px;
          height: 100%;
          position: relative;
          display: flex;
          align-items: center;
          color: #3359c7;
          font-size: 15px;
        }
      }
      .quit {
        width: 150px;
        text-align: center;
        line-height: 40px;
        background: #3359c7;
        position: absolute;
        z-index: 100;
        color: white;
        font-size: 20px;
        right: 0px;
        top: 7vh;
      }
    }
  }
  .rightInner {
    width: 100%;
    height: 93%;
    background: #ebebeb;
  }
}
@media (min-width: 0px) and (max-width: 960px) {
  .manyInput {
    width: 375px !important;
    display: block !important;
    .inputInner {
      margin: auto !important;
      margin-top: 10px !important;
    }
  }
  .closeAndSrue {
    width: 150px;
  }
}
</style>

